package level.editor.view.action.frame;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.beans.PropertyVetoException;

import javax.swing.ImageIcon;

import level.editor.control.layer.LayerControl;
import level.editor.view.action.ActionConstants;
import level.editor.view.action.DesktopAction;
import level.editor.view.desktop.Desktop;
import level.editor.view.frame.InternalFrame;

public class AddLayerControlAction extends DesktopAction
{
	public AddLayerControlAction(Desktop desktop)
	{
		super(FrameConstants.LAYER_TOOL, desktop, ActionConstants.ICON_DIR
				+ "layer.png");
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		InternalFrame frame = new InternalFrame(FrameConstants.LAYER_TOOL,
				new ImageIcon(ActionConstants.ICON_DIR + "layer.png"));
		// hasControl still requires some work
		if (!desktop.hasControl(FrameConstants.LAYER_TOOL))
		{
			frame.setOrigin(new Point(10, 40));
			desktop.add(frame, InternalFrame.Z_ORDER);
			frame.addItem(new LayerControl(desktop.getMainTabbed()));
			try
			{
				frame.setSelected(true);
			}
			catch (PropertyVetoException e1)
			{
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

}
